<template>
  <div class="icons">
    <swiper :options="swiperOption">
      <swiper-slide v-for="(page,index) of pages" :key="index">
        <div class="icon"
             v-for="item of page"
             :key="item.id"
        >
          <router-link :to="item.toUrl" class="icon-img">
            <img class="icon-img-c" :src='item.url'/>
          </router-link>
          <p class="icon-desc">{{ item.description }}</p>
        </div>
      </swiper-slide>
    </swiper>
  </div>
</template>

<script>
import {computed} from "vue";

export default {
  name: 'HomeIcons',
  props: {
    list: Array
  },
  setup(props) {
    const swiperOption = {
      autoplay: false,
      loop: false
    }
    const pages = computed(() => {
      const pages = []
      props.list.forEach((item, index) => {
        const page = Math.floor(index / 8)
        if (!pages[page]) {
          pages[page] = []
        }
        pages[page].push(item)
      })
      return pages
    })
    return {swiperOption, pages}
  }
}
</script>

<style scoped lang="stylus">
@import "~styles/vaibles.styl"
@import "~styles/mixins.styl"
.icons >>> .swiper-container
  height: 0
  padding-bottom 50%

.icons
  margin-top .1rem

  .icon
    position relative
    overflow hidden
    float left
    width 25%
    height 0
    padding-bottom 25%

    .icon-img
      position absolute
      top 0
      left 0
      right 0
      bottom .44rem
      box-sizing border-box
      padding .1rem

      .icon-img-c
        display block
        margin 10%
        width 90%
        height 100%

    .icon-desc
      position absolute
      font-size large
      left 0
      right: 0
      bottom 0
      margin-bottom -0.1rem
      height .54rem
      line-height .54rem
      text-align center
      color $darkTextColor
      ellipsis()
</style>
